﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;

public partial class Person_Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                MembershipUser userOne = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                SqlDataReader reader=WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL("select * from PersonInfo where email='" + userOne.Email + "'");
                if (!reader.Read())
                    throw new Exception();
                PersonInfoData person = PersonInfoDataFactory.Construct(reader);
                reader.Close();
                DropDownList1.Text = person.Title;
                FirstName.Text = person.FirstName;
                LastName.Text = person.LastName;
                Organization.Text = person.Organization;
                Department.Text = person.Department;
                DropDownList2.Text = person.Country;
                Address.Text = person.Address;
                hfID.Value = person.ID.ToString();
            }
            catch
            {
                Response.Redirect("~/Index.aspx");
            }
            
        }
    }
    protected void StepNextButton_Click(object sender, EventArgs e)
    {
        MembershipUser userOne = Membership.GetUser(HttpContext.Current.User.Identity.Name);
        PersonInfoData person = new PersonInfoData();
        person.ID = Convert.ToInt32(hfID.Value);
        person.email = userOne.Email;
        person.Title = DropDownList1.Text;
        person.FirstName = FirstName.Text;
        person.LastName = LastName.Text;
        person.Organization = Organization.Text;
        person.Department = Department.Text;
        person.Country = DropDownList2.Text;
        person.Address = Address.Text;
        PersonInfoDataDBOption.Update(person);
        WFWebLib.WFGlobal.ShowAlertAndRedirect(this, "Modify Success!", "RegistrationStatus.aspx");
    }
}